package com.mybatiscore.jiaocheng.d04mybatis动态Sql;

import com.mybatiscore.Mapper.StudentMapper;
import com.mybatiscore.POJO.Student;
import com.mybatiscore.Util.SqlSessionUtil;
import org.apache.ibatis.session.SqlSession;
import org.junit.Test;

import java.util.List;

public class d05_choose_when_otherwise {
    /*
     choose、when、otherwise标签：如java中的if() else if() else
        <choose>
            <when test=""></when>
            <when test=""></when>
            <otherwise></otherwise>
        <choose>
       当其中某个when条件成立，执行该分支的子句；所有when条件都不满足，将执行otherwise中的子句
     */
    @Test
    public void testChoose(){
        SqlSession sqlSession = SqlSessionUtil.openSession();
        StudentMapper mapper = sqlSession.getMapper(StudentMapper.class);
        //全不为null
        List<Student> students1 = mapper.selectChoose(18, 1.82,'男');
        for(Student s:students1){
            System.out.println(s);
        };

        //第一个为null
        List<Student> students2 = mapper.selectChoose(null, 1.82,'男');
        for(Student s:students2){
            System.out.println(s);
        };

        //一、二为null
        List<Student> students3 = mapper.selectChoose(null, null,'男');
        for(Student s:students3){
            System.out.println(s);
        };

    }
}
